package com.dingwei.lesyndrome.ui.activity;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.widget.EditText;

import com.dingwei.lesyndrome.R;
import com.dingwei.lesyndrome.mvp.presenter.ModifyNamePresenter;
import com.dingwei.lesyndrome.mvp.view.Contract;
import com.lihao.baselibrary.base.BaseActivity;
import com.lihao.baselibrary.weight.TitleBar;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * Created time 2018/3/1.
 * Creator 南柯一梦丶 on
 * Personal signature 余生还长 何必慌张
 * Page description : 修改昵称
 */

public class ModifyNameActivity extends BaseActivity implements Contract.ModifyNameView {

    ModifyNamePresenter modifyNamePresenter = new ModifyNamePresenter(this);

    @Bind(R.id.title_bar)
    TitleBar titleBar;
    @Bind(R.id.et_name)
    EditText etName;

    @Override
    protected int getContentViewId() {
        return R.layout.activity_modify_name;
    }

    @Override
    protected void initData() {

    }

    @Override
    protected void initView() {

        etName.setText(getIntent().getStringExtra("nickname"));

        titleBar.setOnMenuListener(new TitleBar.OnMenuListener() {
            @Override
            public void onMenuClick() {
                modifyNamePresenter.saveName(etName.getText().toString());
            }
        });
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // TODO: add setContentView(...) invocation
        ButterKnife.bind(this);
    }

    @Override
    public void saveNickNameSuccess(String nickname) {
        BaseActivity.value.setUserName(nickname);
        intent = new Intent();
        intent.putExtra("nickname", nickname);
        setResult(Activity.RESULT_OK, intent);
        finish();
    }
}
